﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FuzzyTaskList"
    x:Class="FuzzyTaskList.MainWindow"
    Title="Fuzzy Task List" Height="500.5" Width="1000" 
    WindowStartupLocation="CenterScreen" 
    Closing="Window_Closing" 
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2006" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" >
    <Window.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ResDict.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="TaskNameTemplate" >
                <TextBlock Text="{Binding Path=TaskName}" FontWeight="Bold" FontSize="15" />
            </DataTemplate>

            <ItemsPanelTemplate x:Key="HorizontalPanelTemplate">
                <VirtualizingStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>


            <Style x:Key="tbStyle"  BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="{x:Type ToggleButton}" >
                <Setter Property="IsChecked" Value="{Binding Path=IsActivityComplete}" />
                <Setter Property="Margin" Value="-0.5,-0.5,-0.5,-0.5"/>
                <Setter Property="Height" Value="20"/>
                <Setter Property="Width" Value="15"/>
                <Setter Property="ClickMode" Value="Press"/>
                <Setter Property="IsTabStop" Value="False"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="Late">
                        <Setter Property="Background" Value="Red" />
                        <Setter Property="IsEnabled" Value="true" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="NotActive">
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="IsEnabled" Value="false" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="CanAct">
                        <Setter Property="Background" Value="Aquamarine" />
                        <Setter Property="IsEnabled" Value="true" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="ShouldAct">
                        <Setter Property="Background" Value="YellowGreen" />
                        <Setter Property="IsEnabled" Value="true" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="TooSoon">
                        <Setter Property="Background" Value="SandyBrown" />
                        <Setter Property="IsEnabled" Value="true" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ActivityStatus}" Value="IsComplete">
                        <Setter Property="Background" Value="Green" />
                        <Setter Property="IsEnabled" Value="true" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
            <DataTemplate x:Key="ActivityItemTemplate">
                <ToggleButton  Style="{StaticResource tbStyle}" ToolTip="{Binding ActivityDate}" />
            </DataTemplate>
            <DataTemplate x:Key="HistoryViewDT">
                <ListBox  Height="25"   
                         ItemsSource="{Binding Path=HistoryView}" 
                         ItemsPanel="{DynamicResource HorizontalPanelTemplate}" 
                         ItemTemplate="{DynamicResource ActivityItemTemplate}"  />

            </DataTemplate>
            
        </ResourceDictionary>
    </Window.Resources>

    <Window.CommandBindings>
        <CommandBinding Command="local:MainWindow.AddTaskCommand" Executed="AddTaskHandler" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="SaveTasksHandler" />
    </Window.CommandBindings>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="267*" />
            <ColumnDefinition Width="711*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="29.997*" />
            <RowDefinition Height="307.747*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <ToolBarTray  VerticalAlignment="Top" Grid.ColumnSpan="2" Height="27">
            <ToolBar   Name="toolBar1" VerticalAlignment="Top" SnapsToDevicePixels="False">
                <Button Name="button1" Command="local:MainWindow.AddTaskCommand" >Add Task</Button>
                <Button   Name="button2"  Command="ApplicationCommands.Save" >Save</Button>
            </ToolBar>
        </ToolBarTray>
        
        <ListBox Name="lbTasks"
                 Grid.Row="1"  
                 ItemsSource="{Binding Path=TaskCollection}" 
                 IsSynchronizedWithCurrentItem="True"
                 ItemTemplate="{DynamicResource TaskNameTemplate}" />

        <ListBox ItemsSource="{Binding Path=TaskCollection}"                  
                 Grid.Row="1" 
                 Grid.Column="1"  
                 ItemTemplate="{StaticResource HistoryViewDT}" />


        <local:EditTaskItemUserControl 
            x:Name="editTaskControl" 
            DataContext="{Binding ElementName=lbTasks, Path=SelectedItem}"
            Grid.Row="2" 
            Grid.ColumnSpan="2" 
 />
    </Grid>
</Window>
